package com.manager.core.ad.mediation;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import com.bykv.vk.openvk.CSJAdError;
import com.bykv.vk.openvk.CSJSplashAd;
import com.bykv.vk.openvk.CSJSplashCloseType;
import com.bykv.vk.openvk.TTVfNative;
import com.bykv.vk.openvk.TTVfSdk;
import com.bykv.vk.openvk.VfSlot;
import com.bykv.vk.openvk.mediation.manager.MediationAdEcpmInfo;
import com.bykv.vk.openvk.mediation.manager.MediationBaseManager;
import yyee.llee.mmee.base_api_factory.ModuleConfig;
import yyee.llee.mmee.base_api_net.base_api_bean.NATAdInfo;
import yyee.llee.mmee.base_api_net.base_api_bean.NAdError;
import yyee.llee.mmee.pl190.host668.HandleUtils;
import yyee.llee.mmee.pl190.host668.ScreenUtils;
import com.manager.core.ad.action.AdActionListener;
import com.manager.core.ad.bean.NAdBeanCreator;
import com.manager.core.pl190.host668.JWAdBase;
import com.manager.core.pl190.host668.NConst;

public class JWSplashAd extends JWAdBase {

    private String TAG = ModuleConfig.AD_LOG_TAG + "_MediationSplashAd==";

    private CSJSplashAd mCsjSplashAd;

    private TTVfNative.CSJSplashAdListener mCSJSplashAdListener;

    private CSJSplashAd.SplashAdListener mCSJSplashInteractionListener;

    // 上报百度 暂存ecpm和dsp
    private int lastShowEcpm = 0;

    private String lastShowADN = "";

    public JWSplashAd(String placementId) {
        super(placementId);
    }

    @Override
    public void show(Activity appCompatActivity, ViewGroup viewGroup, AdActionListener adActionListener) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] zmxcbzc = new int[] { 2, 12, 34 };
        for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
            int miniPost = jkashdkas;
            for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                    miniPost = zmasdadasd;
                }
            }
            if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                int asdadavavaqvq;
                asdadavavaqvq = zmxcbzc[jkashdkas];
                zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                zmxcbzc[miniPost] = asdadavavaqvq;
            }
        }
        super.show(appCompatActivity, viewGroup, adActionListener);
        if (isReady() && viewGroup != null) {
            viewGroup.removeAllViews();
            HandleUtils.postDelay(exceptionAdRunnable, 4 * 1000);
            viewGroup.setVisibility(View.VISIBLE);
            Log.i(TAG, "开始Show（）");
            if (mCsjSplashAd == null)
                return;
            Log.i(TAG, "mCsjSplashAd != null");
            mCsjSplashAd.setSplashAdListener(mCSJSplashInteractionListener);
            try {
                mCsjSplashAd.showSplashView(viewGroup);
                if (mAdStatus == null)
                    return;
                mAdStatus.setReady(false);
            } catch (Exception e) {
                callAdClose(new NATAdInfo());
            }
        }
    }

    @Override
    protected void load(Context context) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] hajsdhjasd = new int[] { 123, 234, 45 };
        for (int nxzmcbnzmxc = 1; nxzmcbnzmxc < hajsdhjasd.length; nxzmcbnzmxc++) {
            int anbdmbasnmd = hajsdhjasd[nxzmcbnzmxc];
            int hjkhkhlhkjkad;
            for (hjkhkhlhkjkad = nxzmcbnzmxc - 1; hjkhkhlhkjkad >= 0 && anbdmbasnmd < hajsdhjasd[hjkhkhlhkjkad]; hjkhkhlhkjkad--) {
                hajsdhjasd[hjkhkhlhkjkad + 1] = hajsdhjasd[hjkhkhlhkjkad];
            }
            hajsdhjasd[hjkhkhlhkjkad + 1] = anbdmbasnmd;
        }
        /**
         * 注：每次加载开屏广告的时候需要新建一个TTSplashAd，否则可能会出现广告填充问题
         * （ 例如：mTTSplashAd = new TTSplashAd(this, mAdUnitId);）
         */
        Log.i(TAG, "开始load（）");
        if (!(context instanceof Activity)) {
            callLoadFail(new NAdError("-1", "context not is activtiy", "1", "cancel"));
            return;
        }
        VfSlot adSlot = // 单位px
        new VfSlot.Builder().setCodeId(getPlacementId()).setImageAcceptedSize(// 单位px
        ScreenUtils.getScreenWidth(context), ScreenUtils.getScreenHeight(context)).build();
        TTVfNative adNativeLoader = TTVfSdk.getVfManager().createVfNative(context);
        initListeners();
        adNativeLoader.loadSphVs(adSlot, mCSJSplashAdListener = new TTVfNative.CSJSplashAdListener() {

            @Override
            public void onSplashRenderSuccess(CSJSplashAd csjSplashAd) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
                for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
                    int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
                    int asjkdhjaksd;
                    for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                        akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
                    }
                    akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
                }
                /**
                 * 广告渲染成功  5、渲染成功后，展示广告
                 */
                Log.d(TAG, "splash render success");
                mCsjSplashAd = csjSplashAd;
            }

            @Override
            public void onSplashLoadSuccess(CSJSplashAd csjSplashAd) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] hajsdhjasd = new int[] { 123, 234, 45 };
                for (int nxzmcbnzmxc = 1; nxzmcbnzmxc < hajsdhjasd.length; nxzmcbnzmxc++) {
                    int anbdmbasnmd = hajsdhjasd[nxzmcbnzmxc];
                    int hjkhkhlhkjkad;
                    for (hjkhkhlhkjkad = nxzmcbnzmxc - 1; hjkhkhlhkjkad >= 0 && anbdmbasnmd < hajsdhjasd[hjkhkhlhkjkad]; hjkhkhlhkjkad--) {
                        hajsdhjasd[hjkhkhlhkjkad + 1] = hajsdhjasd[hjkhkhlhkjkad];
                    }
                    hajsdhjasd[hjkhkhlhkjkad + 1] = anbdmbasnmd;
                }
                // 广告物料、素材加载成功
                Log.d(TAG, "splash load success");
                mAdStatus.setReady(true);
                callLoadSuccess();
            }

            @Override
            public void onSplashLoadFail(CSJAdError csjAdError) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] zmxcbzc = new int[] { 2, 12, 34 };
                for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
                    int miniPost = jkashdkas;
                    for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                        if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                            miniPost = zmasdadasd;
                        }
                    }
                    if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                        int asdadavavaqvq;
                        asdadavavaqvq = zmxcbzc[jkashdkas];
                        zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                        zmxcbzc[miniPost] = asdadavavaqvq;
                    }
                }
                Log.d(TAG, "splash load fail, errCode: " + csjAdError.getCode() + ", errMsg: " + csjAdError.getMsg());
                mAdStatus.setReady(false);
                callLoadFail(NAdBeanCreator.createAdError(csjAdError));
            }

            @Override
            public void onSplashRenderFail(CSJSplashAd csjSplashAd, CSJAdError csjAdError) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
                for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
                    int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
                    int asjkdhjaksd;
                    for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                        akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
                    }
                    akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
                }
                // 广告渲染失败
                Log.d(TAG, "splash render fail, errCode: " + csjAdError.getCode() + ", errMsg: " + csjAdError.getMsg());
                mAdStatus.setReady(false);
            }
        }, 3500);
    }

    private void initListeners() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
        for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
            int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
            int asjkdhjaksd;
            for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
            }
            akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
        }
        // 广告展示监听器
        this.mCSJSplashInteractionListener = new CSJSplashAd.SplashAdListener() {

            @Override
            public void onSplashAdShow(CSJSplashAd csjSplashAd) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] hajsdhjasd = new int[] { 123, 234, 45 };
                for (int nxzmcbnzmxc = 1; nxzmcbnzmxc < hajsdhjasd.length; nxzmcbnzmxc++) {
                    int anbdmbasnmd = hajsdhjasd[nxzmcbnzmxc];
                    int hjkhkhlhkjkad;
                    for (hjkhkhlhkjkad = nxzmcbnzmxc - 1; hjkhkhlhkjkad >= 0 && anbdmbasnmd < hajsdhjasd[hjkhkhlhkjkad]; hjkhkhlhkjkad--) {
                        hajsdhjasd[hjkhkhlhkjkad + 1] = hajsdhjasd[hjkhkhlhkjkad];
                    }
                    hajsdhjasd[hjkhkhlhkjkad + 1] = anbdmbasnmd;
                }
                adIsShow.set(true);
                Log.d(TAG, "splash show");
                if (mCsjSplashAd != null) {
                    adIsShow.set(true);
                    MediationBaseManager mediationManager = mCsjSplashAd.getMediationManager();
                    if (mediationManager != null) {
                        MediationAdEcpmInfo showEcpm = mediationManager.getShowEcpm();
                        if (showEcpm != null) {
                            callAdShow(NAdBeanCreator.createNATAdInfo(showEcpm));
                            Log.d(TAG, "splashAdAutoSkip");
                            splashAdAutoSkip();
                        }
                    }
                }
            }

            @Override
            public void onSplashAdClick(CSJSplashAd csjSplashAd) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] quiwyieqasdad = new int[] { 12, 34, 3 };
                int asdjasdhjkah;
                // 第一层循环:表明比较的次数, 比如 length 个元素,比较次数为 length-1 次（肯定不需和自己比）
                for (int ahjdgajhsd = 0; ahjdgajhsd < quiwyieqasdad.length - 1; ahjdgajhsd++) {
                    for (int uiqwyeuiqwe = quiwyieqasdad.length - 1; uiqwyeuiqwe > ahjdgajhsd; uiqwyeuiqwe--) {
                        if (quiwyieqasdad[uiqwyeuiqwe] < quiwyieqasdad[uiqwyeuiqwe - 1]) {
                            asdjasdhjkah = quiwyieqasdad[uiqwyeuiqwe];
                            quiwyieqasdad[uiqwyeuiqwe] = quiwyieqasdad[uiqwyeuiqwe - 1];
                            quiwyieqasdad[uiqwyeuiqwe - 1] = asdjasdhjkah;
                        }
                    }
                }
                Log.d(TAG, "splash click");
                if (mCsjSplashAd != null) {
                    MediationBaseManager mediationManager = mCsjSplashAd.getMediationManager();
                    if (mediationManager != null) {
                        callAdClicked(NAdBeanCreator.createNATAdInfo(mediationManager.getShowEcpm()));
                    }
                }
            }

            @Override
            public void onSplashAdClose(CSJSplashAd csjSplashAd, int closeType) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] zmxcbzc = new int[] { 2, 12, 34 };
                for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
                    int miniPost = jkashdkas;
                    for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                        if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                            miniPost = zmasdadasd;
                        }
                    }
                    if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                        int asdadavavaqvq;
                        asdadavavaqvq = zmxcbzc[jkashdkas];
                        zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                        zmxcbzc[miniPost] = asdadavavaqvq;
                    }
                }
                if (closeType == CSJSplashCloseType.CLICK_SKIP) {
                    Log.d(TAG, "开屏广告点击跳过");
                    callAdClose(new NATAdInfo());
                } else if (closeType == CSJSplashCloseType.COUNT_DOWN_OVER) {
                    Log.d(TAG, "开屏广告点击倒计时结束");
                    callAdClose(new NATAdInfo());
                } else if (closeType == CSJSplashCloseType.CLICK_JUMP) {
                    Log.d(TAG, "点击跳转");
                }
            }
        };
    }

    @Override
    public boolean isReady() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] hajsdhjasd = new int[] { 123, 234, 45 };
        for (int nxzmcbnzmxc = 1; nxzmcbnzmxc < hajsdhjasd.length; nxzmcbnzmxc++) {
            int anbdmbasnmd = hajsdhjasd[nxzmcbnzmxc];
            int hjkhkhlhkjkad;
            for (hjkhkhlhkjkad = nxzmcbnzmxc - 1; hjkhkhlhkjkad >= 0 && anbdmbasnmd < hajsdhjasd[hjkhkhlhkjkad]; hjkhkhlhkjkad--) {
                hajsdhjasd[hjkhkhlhkjkad + 1] = hajsdhjasd[hjkhkhlhkjkad];
            }
            hajsdhjasd[hjkhkhlhkjkad + 1] = anbdmbasnmd;
        }
        return mCsjSplashAd != null && mAdStatus.isReady();
    }

    @Override
    protected int getType() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] zmxcbzc = new int[] { 2, 12, 34 };
        for (int jkashdkas = 0; jkashdkas < zmxcbzc.length; jkashdkas++) {
            int miniPost = jkashdkas;
            for (int zmasdadasd = jkashdkas + 1; zmasdadasd < zmxcbzc.length; zmasdadasd++) {
                if (zmxcbzc[zmasdadasd] < zmxcbzc[miniPost]) {
                    miniPost = zmasdadasd;
                }
            }
            if (zmxcbzc[jkashdkas] > zmxcbzc[miniPost]) {
                int asdadavavaqvq;
                asdadavavaqvq = zmxcbzc[jkashdkas];
                zmxcbzc[jkashdkas] = zmxcbzc[miniPost];
                zmxcbzc[miniPost] = asdadavavaqvq;
            }
        }
        return NConst.SPLASH;
    }

    @Override
    public boolean isNeedContentViewShow() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
        for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
            int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
            int asjkdhjaksd;
            for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
            }
            akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
        }
        return true;
    }

    @Override
    public boolean isSelfBiding() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] hajsdhjasd = new int[] { 123, 234, 45 };
        for (int nxzmcbnzmxc = 1; nxzmcbnzmxc < hajsdhjasd.length; nxzmcbnzmxc++) {
            int anbdmbasnmd = hajsdhjasd[nxzmcbnzmxc];
            int hjkhkhlhkjkad;
            for (hjkhkhlhkjkad = nxzmcbnzmxc - 1; hjkhkhlhkjkad >= 0 && anbdmbasnmd < hajsdhjasd[hjkhkhlhkjkad]; hjkhkhlhkjkad--) {
                hajsdhjasd[hjkhkhlhkjkad + 1] = hajsdhjasd[hjkhkhlhkjkad];
            }
            hajsdhjasd[hjkhkhlhkjkad + 1] = anbdmbasnmd;
        }
        return true;
    }

    @Override
    public void onDestory() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] akhsdkjahsdkjah = new int[] { 1, 2, 3 };
        for (int askjdhajkhd = 1; askjdhajkhd < akhsdkjahsdkjah.length; askjdhajkhd++) {
            int asbdhjagdjhka = akhsdkjahsdkjah[askjdhajkhd];
            int asjkdhjaksd;
            for (asjkdhjaksd = askjdhajkhd - 1; asjkdhjaksd >= 0 && asbdhjagdjhka < akhsdkjahsdkjah[asjkdhjaksd]; asjkdhjaksd--) {
                akhsdkjahsdkjah[asjkdhjaksd + 1] = akhsdkjahsdkjah[asjkdhjaksd];
            }
            akhsdkjahsdkjah[asjkdhjaksd + 1] = asbdhjagdjhka;
        }
        super.onDestory();
        adIsShow.set(false);
        removeRunable();
        if (mCsjSplashAd != null && mCsjSplashAd.getMediationManager() != null) {
            mCsjSplashAd.getMediationManager().destroy();
            mCsjSplashAd = null;
        }
    }
}
